package com.gxa.modules.service.impl;

import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.PageRecv;
import com.gxa.common.vo.ResultVo;
import com.gxa.modules.mapper.Loanafter_CheckReportMapper;
import com.gxa.modules.mapper.Loanafter_WarningMapper;
import com.gxa.modules.pojo.Loanafter_Checkreport;
import com.gxa.modules.pojo.Loanafter_Warning;
import com.gxa.modules.service.Loanafter_CheckReportService;
import com.gxa.modules.service.Loanafter_WarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * Created with IntelliJ IDEA.
 * User: 张剑宇
 * Date: 2021/12/27 10:00
 * Description:
 * Version: V1.0
 */
@Service
public class Loanafter_WarningServiceImpl implements Loanafter_WarningService {
    @Autowired(required=false)
    private Loanafter_WarningMapper loanafter_warningMapper;

    //添加贷后预警
    @Override
    public ResultVo addWarning(Loanafter_Warning loanafter_warning) {
        loanafter_warningMapper.addWarning(loanafter_warning);
        ResultVo resultVo=new ResultVo();
        resultVo.setCode(200);
        resultVo.setMsg("添加成功！");
        resultVo.setData(loanafter_warning.getLoanafter_warning_id());
        return  resultVo;
    }

    @Override
    @Cacheable(value="Loanafter_Warning",key = "#id")
    public Loanafter_Warning queryWarningById(Integer id) {
        ResultVo r=new ResultVo();
        Loanafter_Warning loanafter_warning=loanafter_warningMapper.queryWarningById(id);
//        r.setData(loanafter_warning);
//        r.setCode(200);
//        r.setMsg("查询成功！");

        return loanafter_warning;

    }


    //查询贷后预警
    @Override
//    @Cacheable(value = "queryWarningPage",key = "#pageRecv.currentPage")
    public JsonResult queryWarning(PageRecv<Loanafter_Warning> pageRecv) {
        //对查询页面参数计算
        Integer currentPage=pageRecv.getCurrentPage();
        Integer pageSize=pageRecv.getPageSize();
        Integer limit1=(currentPage-1)*pageSize;
        pageRecv.setCurrentPage(limit1);

        //调用Mapper方法获取返回结果
        List<Loanafter_Warning> list=loanafter_warningMapper.queryWarning(pageRecv);
        Integer count=loanafter_warningMapper.queryWarningCount(pageRecv.getData());

        //将结果塞入R
        JsonResult r=new JsonResult();
        r.setData(list);
        r.setCode(200);
        r.setMsg("查询成功！");
        r.setCount(count);
        return r;
    }

    @Override
    public ResultVo upadeWarning(Loanafter_Warning loanafter_warning) {
        loanafter_warningMapper.updateWarning(loanafter_warning);
        ResultVo resultVo=new ResultVo();
        resultVo.setCode(200);
        resultVo.setMsg("修改成功！");
        return resultVo;
    }
//    @Override
//    @CachePut(value = "Loanafter_Warning",key = "#loanafter_warning.loanafter_warning_id")
//    public Loanafter_Warning upadeWarning(Loanafter_Warning loanafter_warning) {
//        loanafter_warningMapper.updateWarning(loanafter_warning);
//
//        return loanafter_warning;
//    }


}
